﻿<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<?php
include '../DataBase/ConnectDB.php';
include '../Home/DefineVar.php';
//include '../Security/CheckUser.php';
/***
 * データベースの接続
 */
mysql_select_db(MYSQL_DATABASE, $link) 
	or exit('Could not select database'.mysql_error());

////////////////////////////////////////////////////////////////////////
/***
 * [POST]メソッドで引数リストを取り出します。
 */
$accountName = mysql_real_escape_string($_POST['accountName']);
$pass = sha1(mysql_real_escape_string($_POST['pass1']));
$fullName = mysql_real_escape_string($_POST['fullName']);
$mail = mysql_real_escape_string($_POST['mail']);
$phone =mysql_real_escape_string($_POST['phone']);
$address =mysql_real_escape_string($_POST['address']);

/***
 * アカウント名が存在したか確認します。
 */
	$query = "SELECT * FROM ".MYSQL_TABLE_USERINFOR." WHERE accountName='$accountName';";
        $result = mysql_query($query, $link);
        if(!$result){
     		print("<br><script type='text/javascript'> alert('".SQL_ERR_MESS."'); window.location ='Register.php';</script> ");
     		exit();
        }
       if(($resultuser = mysql_fetch_row($result)) != false){
		 	print("<br><script type='text/javascript'> alert('".REGISTER_FAIL_MESS."'); window.location ='Register.php';</script> ");
 			exit();
        }
        
        $query = "INSERT INTO ".MYSQL_TABLE_USERINFOR."(accountname, password, name, mail, phone, address) VALUES('$accountName', '$pass', '$fullName', '$mail', '$phone', '$address');";
        //print($query);
        if(($result = mysql_query($query, $link))){
	 		print("<br><script type='text/javascript'> alert('".REGISTER_OK_MESS."'); window.location ='../Home/Home.php';</script> ");
        }
        else
             print("<br><script type='text/javascript'> alert('".SQL_ERR_MESS."'); window.location ='Register.php';</script> ");
	 mysql_close($link);
?>
</body>
</html>